package com.cfuture08.home.action.role;

import com.cfuture08.eweb4j.component.dwz.DWZUtil;
import com.cfuture08.eweb4j.mvc.action.Action;
import com.cfuture08.eweb4j.mvc.action.ActionSupport;
import com.cfuture08.eweb4j.orm.dao.DAO;
import com.cfuture08.home.vo.Role;

public class EditRole extends ActionSupport {
	private Role role;

	public String execute() {
		Role otherRole = DAO.selectOne(role, new String[] { "name" });
		if (otherRole != null && otherRole.getId() != role.getId()) {
			out.print(DWZUtil.getFailedJson("修改角色" + role.getName()
					+ "失败,该角色已经存在"));
		} else {
			out.print(DAO.update(role) == true ? DWZUtil.getSuccessJson("修改角色"
					+ role.getName() + "成功", "xssyjs", "showAllRole.do", null)
					: DWZUtil.getFailedJson("修改角色" + role.getName() + "失败"));
		}
		return Action.AJAX;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}
}
